package csl.mq.rabbitmq.old.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;


/**
 * @Description: TODO 实现消息的监视，到达队列的监视
 * @author: 隔山海
 * @date: 2021年09月02日 17:38
 */
@Slf4j
@Component
public class WatchMessageImpl implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {

    /**
     * Confirmation callback.
     * @param correlationData correlation data for the callback.
     * @param ack             true for ack, false for nack
     * @param cause           An optional cause, for nack, when available, otherwise null.
     */
    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack){
            log.info("send message to exchange successful!");
        }else{
            log.error("send message to exchange error!");
        }
    }

    /**
     * Returned message callback.
     *
     * @param returned the returned message and metadata.
     */
    @Override
    public void returnedMessage(ReturnedMessage returned) {
        log.error("exchange to queue is error!\ndetails:====>{}\n",returned);
        /*处理到达队列失败的回调数据*/
    }
}
